package com.winchain.chainbill.bill.biz.contract.cmd;

import com.shell.bee.contract.ContService;
import com.shell.bee.contract.po.ContBas;
import com.shell.framework.command.CommandContext;
import com.shell.framework.command.ICommand;
import com.shell.framework.utils.CommonDataUtil;
import com.winchain.chainbill.bill.base.po.CbDct;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.po.CbSnd;
import com.winchain.chainbill.bill.base.po.CbXfe;
import com.winchain.chainbill.bill.biz.Bill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ContractCancelCmd<T> implements ICommand<Bill<T>> {
	@Autowired
	private ContService contService;

	public boolean execute(CommandContext<Bill<T>> context) throws Exception {
		CbRec bill = ((Bill) context.getSource()).getRec();
		T source = (T) ((Bill) context.getSource()).getSource();
		String bizType = null;
		if ((source instanceof CbSnd)) {
			bizType = "10";
		} else if ((source instanceof CbXfe)) {
			bizType = "11";
		} else if ((source instanceof CbDct)) {
			bizType = "12";
		}
		ContBas cont = this.contService.getLatestCont(CommonDataUtil.getCurEntId(), bill.getBillId(), bizType, null);
		if (cont != null) {
			cont.setContState("0");
			this.contService.updateCont(cont);
		}
		return false;
	}
}
